* @param string $location
*/
public function __construct( $location ) {
- $this->hash = md5_file( $location );
$this->contents = json_decode( file_get_contents( $location ), true );
}
- public function getHash() {
- return $this->hash;
- }
-
/**
* Dependencies as specified by composer.json
*
$this->contents = json_decode( file_get_contents( $location ), true );
}
- public function getHash() {
- return $this->contents['hash'];
- }
-
/**
* Dependencies currently installed according to composer.lock
*
$lock = new ComposerLock( $lockLocation );
$json = new ComposerJson( $jsonLocation );
- if ( $lock->getHash() === $json->getHash() ) {
- $this->output( "Your composer.lock file is up to date with current dependencies!\n" );
- return;
- }
- // Out of date, lets figure out which dependencies are old
+ // Check all the dependencies to see if any are old
$found = false;
$installed = $lock->getInstalledDependencies();
foreach ( $json->getRequiredDependencies() as $name => $version ) {
1
);
} else {
- // The hash is the entire composer.json file,
- // so it can be updated without any of the dependencies changing
// We couldn't find any out-of-date dependencies, so assume everything is ok!
$this->output( "Your composer.lock file is up to date with current dependencies!\n" );
}
$this->json2 = "$IP/tests/phpunit/data/composer/new-composer.json";
}
- public static function provideGetHash() {
- return [
- [ 'json', 'cc6e7fc565b246cb30b0cac103a2b31e' ],
- [ 'json2', '19921dd1fc457f1b00561da932432001' ],
- ];
- }
-
- /**
- * @dataProvider provideGetHash
- * @covers ComposerJson::getHash
- */
- public function testIsHashUpToDate( $file, $expected ) {
- $json = new ComposerJson( $this->$file );
- $this->assertEquals( $expected, $json->getHash() );
- }
-
/**
* @covers ComposerJson::__construct
* @covers ComposerJson::getRequiredDependencies
$this->lock = "$IP/tests/phpunit/data/composer/composer.lock";
}
- /**
- * @covers ComposerLock::getHash
- */
- public function testGetHash() {
- $lock = new ComposerLock( $this->lock );
- $this->assertEquals( 'a3bb80b0ac4c4a31e52574d48c032923', $lock->getHash() );
- }
-
/**
* @covers ComposerLock::__construct
* @covers ComposerLock::getInstalledDependencies